package com.zealcomm.ivcscustomer.fragment

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.zco.base.entity.Command
import com.zco.base.entity.CommandConfirmBaseBean
import com.zco.base.entity.SessionMessage
import com.zco.base.entity.SummaryConfirmBean
import com.zealcomm.commonui.base.ViewBindingFragment
import com.zealcomm.ivcscustomer.databinding.FragmentSummaryConfirmBinding
import com.zealcomm.ivcscustomer.databinding.ItemSummaryConfirmBinding

class SummaryConfirmFragment(summaryConfirmSessionMessage: SessionMessage<Command<CommandConfirmBaseBean<MutableList<SummaryConfirmBean>>>>) :
    ViewBindingFragment<FragmentSummaryConfirmBinding>() {
    private val summaryConfirmSessionMessage = summaryConfirmSessionMessage
    private val data = mutableListOf<SummaryConfirmBean>()

    init {
        summaryConfirmSessionMessage.data.data.content?.let {
            data.addAll(it)
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        PagerSnapHelper().attachToRecyclerView(binding?.rvImage)
        binding?.rvImage?.adapter = object : RecyclerView.Adapter<MyViewHolder>() {
            override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
                return MyViewHolder(
                    ItemSummaryConfirmBinding.inflate(
                        layoutInflater,
                        parent,
                        false
                    )
                )
            }

            override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
                Glide.with(context!!.applicationContext).load(data[position].url)
                    .into(holder.binding.ivContent)
            }

            override fun getItemCount(): Int {
                return data.size
            }

        }
    }

    private class MyViewHolder(binding: ItemSummaryConfirmBinding) :
        RecyclerView.ViewHolder(binding.root) {
        var binding = binding
    }
}